package com.kupurui.asteacher.ui.job;

import android.text.Html;
import android.view.View;
import android.widget.TextView;

import com.android.frame.util.AppJsonUtil;
import com.kupurui.asteacher.R;
import com.kupurui.asteacher.bean.ScriptTopicInfo;
import com.kupurui.asteacher.http.Teacher;
import com.kupurui.asteacher.ui.BaseAty;
import com.kupurui.asteacher.utils.URLImageParser;

import butterknife.Bind;
import butterknife.OnClick;
import okhttp3.Call;
import okhttp3.Response;

/**
 * 原题
 * Created by Administrator on 2017/7/25.
 */

public class ScriptTopicAty extends BaseAty {

    @Bind(R.id.tv_back)
    TextView tvBack;
    @Bind(R.id.tv_title)
    TextView tvTitle;
    @Bind(R.id.tv_subject)
    TextView tvSubject;
    @Bind(R.id.tv_answer)
    TextView tvAnswer;
    @Bind(R.id.tv_analysis)
    TextView tvAnalysis;

    private String q_id = "";
    ScriptTopicInfo scriptTopicInfo;

    @Override
    public int getLayoutId() {
        return R.layout.script_topic_aty;
    }

    @Override
    public void initData() {
        if (getIntent().getExtras() != null) {
            q_id = getIntent().getStringExtra("q_id");
        }
    }

    @Override
    public void requestData() {
        showLoadingContent();
        new Teacher().questionDetail(q_id, this, 0);
    }

    @OnClick({R.id.tv_back})
    @Override
    public void onClick(View view) {
        super.onClick(view);
        switch (view.getId()) {
            case R.id.tv_back:
                finish();
                break;
        }
    }

    @Override
    public void onSuccess(String result, Call call, Response response, int what) {
        switch (what) {
            case 0:
                scriptTopicInfo = AppJsonUtil.getObject(result, ScriptTopicInfo.class);
                tvSubject.setText(Html.fromHtml(scriptTopicInfo.getTitle(), new URLImageParser(this,tvSubject), null));
                tvAnswer.setText(Html.fromHtml(scriptTopicInfo.getTrue_answer(), new URLImageParser(this,tvAnswer), null));
                tvAnalysis.setText(Html.fromHtml(scriptTopicInfo.getAnalysis(), new URLImageParser(this,tvAnalysis), null));
                break;
        }
        super.onSuccess(result, call, response, what);
    }

}
